// 导入需要的config和request
import confing from '../config/config.js';
import request from '../util/request.js';
// 申明请求对象
const defectRequst = {
    BASE_URL: confing.QC_URL + "/defect",

    //多选删除按钮
    deletes(defectIds,callback){
        //拼接URL
        let url=this.BASE_URL+"/deletes?t=1";
        if(defectIds !=undefined){
            defectIds.forEach(defectId =>{
                url +="&defectId="+defectId;
            })
          request.delete(url,callback);
        }
    },


    //删除缺陷信息
    delete(defectId,callback){
        
        request.delete(this.BASE_URL + "/" + defectId,callback);
    },

    //编辑缺陷信息
    edit(defect,callback){
        if(defect != undefined && defect.defectId != undefined){
            request.put(this.BASE_URL + "/update",defect,callback);
        }

    },
    //根据id查询缺陷信息
    get(defectId,callback){
        if(defectId){
            // 准备url
            let url = this.BASE_URL + "/get?defectId=" + defectId;
            request.get(url,callback);
        }
        
    },


    //保存缺陷信息
    save(defect, callback) {
        if (defect) {
            request.post(this.BASE_URL + "/save", defect, callback);
        }
    },


    // 请求的API
    list(page = 1, limit = 10, defect, callbcak) {
        // url
        let url = this.BASE_URL + "/list?page=" + page +
            "&limit=" + limit;
        if (defect) {
            if (defect.defectName) {
                url += "&defectName=" + defect.defectName;
            }
            if (defect.defectType) {
                url += "&defectType=" + defect.defectType;
            }
            if (defect.defectLevel) {
                url += "&defectLevel=" + defect.defectLevel;
            }
        }
        // 发送请求
        request.get(url, callbcak);
    }

}

// 将dictRequest暴漏出去
export default defectRequst;